﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.Collections.Generic;
// 此页面函数全部为内部调用接口，不供外部调用
namespace WebServiceSmart
{
    partial class MyService
    {



        //加入状态
        private int SaveGoodsStatus( mysqlcli mainsql,string Listbiaoname, string Account,
            string AccountName, string Biao_Id, string status,
            string worker, string machine, string biaodefault)
        {
            try
            {
                string cmd = string.Format("insert into {0} values(NULL,'{1}'" +
                    ",'{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
                     Listbiaoname, Account,AccountName,
                     Biao_Id, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                     status, worker, machine, biaodefault);
                int ret = mainsql.SqlExcuteNoReturn(cmd);
                if (ret == 1)
                {
                    return 1;
                }
                else
                {
                   
                    return -1;
                }
            }
            catch
            {
        
                return -1;
            }
        }




        /// <summary>
        /// 将DataTable转换为Json格式
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public string CreateJsonParameters(DataTable dt)
        {
            StringBuilder JsonString = new StringBuilder();
            if (dt != null && dt.Rows.Count > 0)
            {
                JsonString.Append("{");
                JsonString.Append("\"Head\":[");

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    JsonString.Append("{");
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        if (j < dt.Columns.Count - 1)
                        {
                            JsonString.Append("\"" + dt.Columns[j].ColumnName.ToString() +
                                  "\":" + "\"" +
                                  dt.Rows[i][j].ToString() + "\",");
                        }
                        else if (j == dt.Columns.Count - 1)
                        {
                            JsonString.Append("\"" +
                               dt.Columns[j].ColumnName.ToString() + "\":" +
                               "\"" + dt.Rows[i][j].ToString() + "\"");
                        }
                    }
                    if (i == dt.Rows.Count - 1)
                    {
                        JsonString.Append("}");
                    }
                    else
                    {
                        JsonString.Append("},");
                    }
                }

                JsonString.Append("]}");
                return JsonString.ToString();
            }
            else
            {
                return null;
            }
        }
    }
}
